package com.tm.mholmu.db;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import android.util.Log;

public class DBPoliceHelper extends SQLiteOpenHelper {
  
	private static final String TAG = "DBUtils";
	public static final String DATABASE_NAME = "mho.db";
	private static final int DATABASE_VERSION = 1;
	private Context mContext;

	public interface Tables {
	
		public static final String  Dase_Data= "Dase_data";
		public static final String  Skill_Data="Skill_Data";
	}
	
	
	/**
	 * 基本数据
	 * @author CTX
	 *
	 */
	public interface BaseData {
		/** 名称 */
		public static final String name = "名称";
		/** 远近  */
		public static final String distance = "远近";
		/**部位  */
		public static final String part = "部位";
		/**孔*/
		public static final String hole = "孔";

		/**装备id*/
		public  static final String id = "id";

		/**拥有技能*/
		public static final String skill = "拥有技能";
		/**依次N_*是相对应的技能*/
		public static final String N_1="技能1";
		public static final String N_2="技能2";
		public static final String N_3="技能3";
		public static final String N_4="技能4";
		public static final String N_5="技能5";
		public static final String N_6="技能6";
		/**依次Z_*是相对应的技能值*/
		public static final String Z_1="技能值1";
		public static final String Z_2="技能值2";
		public static final String Z_3="技能值3";
		public static final String Z_4="技能值4";
		public static final String Z_5="技能值5";
		public static final String Z_6="技能值6";
	}
	
	
	public interface SkillData  {
		public String Name="名称";
		public String Comment="内容";
		public String Id="id";
		public String Id2="id2";
		public String Point="值";
	}
	
	
	public DBPoliceHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		mContext = context;
	}

	/** 开始初始化创建所以的表 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE " + Tables.Dase_Data + " ("
				+ BaseData.id + " INTEGER PRIMARY KEY AUTOINCREMENT, "
				+ BaseData.name + " TEXT NOT NULL, "
				+ BaseData.distance + " TEXT NOT NULL, "
				+ BaseData.part + " TEXT NOT NULL,"
				+ BaseData.hole + " INTEGER NOT NULL,"
				+ BaseData.skill + " TEXT NOT NULL,"
				+ BaseData.N_1 + " INTEGER NOT NULL,"
				+ BaseData.N_2 + " INTEGER NOT NULL,"
				+ BaseData.N_3 + " INTEGER NOT NULL,"
				+ BaseData.N_4 + " INTEGER NOT NULL,"
				+ BaseData.N_5 + " INTEGER NOT NULL,"
				+ BaseData.N_6 + " INTEGER NOT NULL,"
				+ BaseData.Z_1 + " INTEGER NOT NULL,"
				+ BaseData.Z_2 + " INTEGER NOT NULL,"
				+ BaseData.Z_3 + " INTEGER NOT NULL,"
				+ BaseData.Z_4 + " INTEGER NOT NULL,"
				+ BaseData.Z_5 + " INTEGER NOT NULL,"
				+ BaseData.Z_6 + " INTEGER NOT NULL"
				+");");
	
		db.execSQL("CREATE TABLE " + Tables.Skill_Data + " ("
				+ SkillData.Id + " INTEGER PRIMARY KEY AUTOINCREMENT, "
				+ SkillData.Id2 + " INTEGER NOT NULL, "
				+ SkillData.Name + " TEXT NOT NULL, "
				+ SkillData.Point + " INTEGER NOT NULL,"
				+ SkillData.Comment + " TEXT NOT NULL"
				+");");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		int upgradeVersion = oldVersion;
		if (upgradeVersion != newVersion) {
			Log.w(TAG, "Got stuck trying to upgrade from version "
					+ upgradeVersion + "," + " must wipe the settings provider");

			SharedPreferences pre = mContext.getSharedPreferences(
					"LocusPassWordView.class.getName()", 0);
			Editor edit = pre.edit();
			edit.putLong("lastCheckApTime", 0);
			edit.commit();
			db.execSQL("DROP TABLE IF EXISTS " + Tables.Dase_Data);

			//db.execSQL("DROP TABLE IF EXISTS " + Tables.GPS_INFO);
			onCreate(db);
		}
	}

}
